<?php
namespace Tongcheng\Controller;
use Think\Controller;
use Think\Model;

/**
 * Class BooksBackController
 * @package Tongcheng\Controller
 *
 * 关于我们管理
 */
class AboutUsBackController extends CommonController {
    /**
     * 关于我们管列表
     */
    public function index(){

//        $model = M("Books");
//        $map = array();
////        $map['wid'] = 2;//小程序id，固定2
////        $map['status'] = 1;
//        // $map['is_pay'] = 1;
//
//        $res['count'] = $model->where($map)->count();
//        $page = $_GET['page']?$_GET['page']:1;
//        $limit = $_GET['limit']?$_GET['limit']:10;
//        $list = $model->field("tp_books.*,s.nickname,FROM_UNIXTIME(tp_books.add_time,\"%m-%d %H:%i\") time")->join("tp_member s on s.uid = tp_books.uid",'left')->where()->page("{$page},{$limit}")->order('id desc')->select();
//        $res['list']= $list;
//        if(IS_AJAX){
//            $this->ajaxReturn($res);
//        }else{
//            $this->assign('res', $res);
//            $this->display();
//        }
        $aboutus = '';
        $result = M('Aboutus')->where('type = 1')->select();
        if(!empty($result[0])){
            $aboutus = $result[0];
        }
        $this->assign('res', $aboutus);
        $this->display();
    }

    /**
     * 查看关于我们
     */
    public function edit(){
        $info = $_POST;
        $id = $_POST['id'];
        $_POST['add_time']=time();
        $_POST['type']=1;//关于我们
        $result ='';
        if(!empty($id)){
            $result = M('Aboutus')->where('id = '.$id)->save($_POST);
        }else{
            $result = M('Aboutus')->add($_POST);
        }

        if($result){
            $this->ajaxReturn(1);
        }else{
            $this->ajaxReturn(0);
        }

    }

    /**
     * 删除关于我们
     */
    public function del(){
        $id = I('id');
        if(empty($id)){
           $this->ajaxReturn(0);
        }
        $result = M('Books')->where('id = '.$id)->delete();
        if($result){
            $this->ajaxReturn(1);
        }else{
            $this->ajaxReturn(0);
        }
    }
}